define(function(require, exports, module){
	var mycollectdetailTemp = require("text!../template/mycollectdetail.html");
	
	module.exports = Nuui.View.extend({
		
		template:mycollectdetailTemp,
		
		onRender:function(){
			var view = this;
            var title=App.storage.get('title');
            var number=App.storage.get('number');
            /*判断路由，给头部加类*/
            var r =window.location.href;
            r = r.substring(r.indexOf("#"),r.length);
			if(r == "#example/index/mycollectdetail"){
				$("header>div").addClass("bg-header")
			}
			App.request(App.server.getServePath(App.path.collectAllAction), {
				success:function(data){
					if(data.ec){
						alert(data.em);
					}else{
						var groupList = data.collectList.GovernmentAdviser.list;
                        var tpl= '';
                        for(var i = 0; i < groupList.length; i++){
                            if(groupList[i].classify==title){
                                tpl += '<div class="all" data-code="'+groupList[i].code+'" data-productCode="'+groupList[i].productCode+'">\n' +
                                    '\t\t\t\t<ul>\n' +
                                    '\t\t\t\t\t<li class="collect_list">\n' +
                                    '\t\t\t\t\t\t<div class="img_left">\n' +
                                    '\t\t\t\t\t\t\t<img src="../../../images/collect/'+groupList[i].avatar+'" alt="">\n' +
                                    '\t\t\t\t\t\t</div>\n' +
                                    '\t\t\t\t\t\t<div class="poll_right">\n' +
                                    '\t\t\t\t\t\t\t<h3>'+groupList[i].name+'</h3>\n' +
                                    '\t\t\t\t\t\t\t<p><span>'+groupList[i].data+'</span><span>'+groupList[i].time+'</span><img class="cancel_btn" src="../../../images/collect/'+groupList[i].collectIcon+'" alt=""></p>\n' +
                                    '\t\t\t\t\t\t</div>\n' +
                                    '\t\t\t\t\t</li>\n' +
                                    '\t\t\t\t</ul>\n' +
                                    '\t\t\t</div>';
                                view.$("#collectdetail1").html(tpl);
							}
						}
						var tpl1='<h1>'+title+'</h1>\n' +
                            '     <p>共 <span>'+number+'</span>个</p>';
                        view.$(".collectdetail1-top").html(tpl1);
					  }
				  }
			 });
		},
		
		onShow:function(){
			 var view=this;
			 view.$('#collectdetail1').on('tap','.all .cancel_btn',function(e){
					e.stopPropagation();
					e.cancelBubble=true;
					var target=$(this).closest('.all');
					$(target).addClass('active').delay(300).queue(function(){
						$(this).remove();
						$(this).dequeue();
					})
				})
			 view.$('#collectdetail1').on('tap','.all',function(){
				 App.storage.set('productCode',$(this).attr('data-productCode'));
				 App.storage.set('yunCode',$(this).attr('data-code'));
				 App.navigate("example/index/MDM",true);
				 return false;
			 })
		}
		
	});	
});